package com.penta.util;

import java.io.Serializable;


public class JsonResult<T> implements Serializable {

    public static final int SUCESS_CODE = 200;
    public static final int FAIL_CODE = 500;
    private boolean success = true;
    private String message = "";
    private boolean show = true;
    private int code = 200;
    private T data;

    public JsonResult() {
    }

    public JsonResult(boolean success) {
        this.success = success;
        if (success) {
            this.code = 200;
        } else {
            this.code = 500;
        }

    }

    public static JsonResult Success(String message) {
        JsonResult result = new JsonResult(true, message);
        return result;
    }

    public static JsonResult Success() {
        JsonResult result = new JsonResult(true);
        return result;
    }

    public static JsonResult Fail(String message) {
        JsonResult result = new JsonResult(false, message);
        return result;
    }

    public static JsonResult Fail() {
        JsonResult result = new JsonResult(false);
        return result;
    }

    public JsonResult(boolean success, String message) {
        this.success = success;
        this.message = message;
        if (success) {
            this.code = 200;
        } else {
            this.code = 500;
        }

    }

    public JsonResult(boolean success, T data, String message) {
        this.success = success;
        if (success) {
            this.code = 200;
        } else {
            this.code = 500;
        }

        this.data = data;
        this.message = message;
    }

    public JsonResult(int code, T data, String message) {
        if (code == 200) {
            this.success = Boolean.TRUE;
        } else {
            this.success = Boolean.FALSE;
        }

        this.data = data;
        this.message = message;
    }

    public static JsonResult getSuccessResult(String msg) {
        return getSuccessResult((Object)null, 200, msg);
    }

    public static <T> JsonResult getSuccessResult(T data, String msg) {
        return getSuccessResult(data, 200, msg);
    }

    public static <T> JsonResult getSuccessResult(T data) {
        return getSuccessResult(data, 200, "");
    }

    public static <T> JsonResult getSuccessResult(T data, Integer code, String msg) {
        JsonResult<T> result = new JsonResult();
        result.setSuccess(true);
        result.setData(data);
        result.setCode(200);
        result.setMessage(msg);
        return result;
    }

    public static JsonResult getFailResult(String msg) {
        return getFailResult((Object)null, 500, msg);
    }

    public static JsonResult getFailResult(String msg, int code) {
        return getFailResult((Object)null, code, msg);
    }

    public static <T> JsonResult getFailResult(T data, String msg) {
        return getFailResult(data, 500, msg);
    }

    public static <T> JsonResult getFailResult(T data, Integer code, String msg) {
        JsonResult<T> result = new JsonResult();
        result.setSuccess(false);
        result.setData(data);
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }


    public boolean isSuccess() {
        return this.success;
    }

    public String getMessage() {
        return this.message;
    }

    public boolean isShow() {
        return this.show;
    }

    public int getCode() {
        return this.code;
    }

    public T getData() {
        return this.data;
    }

    public JsonResult<T> setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public JsonResult<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public JsonResult<T> setShow(boolean show) {
        this.show = show;
        return this;
    }

    public JsonResult<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public JsonResult<T> setData(T data) {
        this.data = data;
        return this;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof JsonResult)) {
            return false;
        } else {
            JsonResult<?> other = (JsonResult)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.isSuccess() != other.isSuccess()) {
                return false;
            } else if (this.isShow() != other.isShow()) {
                return false;
            } else if (this.getCode() != other.getCode()) {
                return false;
            } else {
                Object this$message = this.getMessage();
                Object other$message = other.getMessage();
                if (this$message == null) {
                    if (other$message != null) {
                        return false;
                    }
                } else if (!this$message.equals(other$message)) {
                    return false;
                }

                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof JsonResult;
    }
}
